package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.NavService;
import com.cn.wanxi.service.NewsService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;
import com.cn.wanxi.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        封装公司信息
//        匿名内部类
//        CompanyService companyService =new CompanyService() {
//            @Override
//            public CompanyModel getCompanyModel() {
//                return null;
//            }
//        };
        CompanyService companyService = new CompanyServiceImpl();
        CompanyModel companyModel = companyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);
//        封装导航信息
        NavService navService = new NavServiceImpl();
        NavModel[] navModels = navService.getNavModels();
        req.setAttribute("navModels", navModels);
//        封装新闻信息
        NewsService newsService=new NewsServiceImpl();
        NewsModel[] newsModels=newsService.getNewsModelsForHomePage();
        req.setAttribute("newsModels",newsModels);
        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);
    }
}
